#ifndef QAVDEMUXER_H
#define QAVDEMUXER_H

#include "qavpacket_p.h"
#include "qavstream.h"
#include "qavframe.h"
#include "qavsubtitleframe.h"

#include <memory>

#include <QObject>
#include <QMap>

QT_BEGIN_NAMESPACE

class QAVDemuxerPrivate;
class QAVVideoCodec;
class QAVAudioCodec;
class QAVIODevice;
struct AVStream;
struct AVCodecContext;
struct AVFormatContext;
class QAVDemuxer : public QObject
{
public:
    QAVDemuxer(QObject* parent = nullptr);
    ~QAVDemuxer();

    void abort(bool stop = true);
    int load(const QString &url);
    void unload();

    QAVStream stream(int index) const;
    QList<QAVStream> videoStreams() const;
    QAVStream videoStream() const;
    bool setVideoStream(const QAVStream &stream);
    QList<QAVStream> audioStreams() const;
    QAVStream audioStream() const;
    bool setAudioStream(const QAVStream &stream);

    QList<QAVStream> subtitleStreams() const;
    QAVStream subtitleStream() const;
    bool setSubtitleStream(const QAVStream &stream);

    QAVPacket read();

    bool decode(const QAVPacket &pkt, QAVFrame &frame) const;
    bool decode(const QAVPacket &pkt, QAVSubtitleFrame &frame) const;

    double duration() const;
    bool seekable() const;
    int seek(double sec);
    bool eof() const;
    double videoFrameRate() const;

    QMap<QString, QString> metadata() const;

    QString bitstreamFilter() const;
    int applyBitstreamFilter(const QString &bsfs);

    QString inputFormat() const;
    void setInputFormat(const QString &format);

    QString inputVideoCodec() const;
    void setInputVideoCodec(const QString &codec);

    static QStringList supportedFormats();
    static QStringList supportedVideoCodecs();
    static QStringList supportedProtocols();
    static QStringList supportedBitstreamFilters();

protected:
    std::unique_ptr<QAVDemuxerPrivate> d_ptr;

private:
    Q_DISABLE_COPY(QAVDemuxer)
    Q_DECLARE_PRIVATE(QAVDemuxer)
};

QT_END_NAMESPACE

#endif
